import pkRequest from '@/service'
import type {
  ICancelOrder,
  ICreateOrder,
  IOrderConfig,
  IOrderInfo,
  IOrderStatus,
  IPayResultStatus,
  IUserOrderList,
  IWXPayErcode
} from './type'

enum API_ORDER {
  CREATE_ORDER = '/api/order/orderInfo/auth/submitOrder',
  GET_ORDERINFO_BY_ID = '/api/order/orderInfo/auth/getOrderInfo',
  CANCEL_ORDER_BY_ORDERID = '/api/order/orderInfo/auth/cancelOrder',
  PAY_WXERCODE_BY_ORDERID = '/api/order/weixin/createNative',
  ORDER_PAYSTATUS_BY_ORDERID = '/api/order/weixin/queryPayStatus',
  GET_USERORDER_LIST = '/api/order/orderInfo/auth',
  ORDER_STATUS_LIST = '/api/order/orderInfo/auth/getStatusList'
}

// 创建订单
// /api/order/orderInfo/auth/submitOrder/{hoscode}/{scheduleId}/{patientId}
export const postCreateOrderBy = (
  hoscode: string,
  scheduleId: string,
  patientId: number
) => {
  return pkRequest.post<ICreateOrder>({
    url: API_ORDER.CREATE_ORDER + `/${hoscode}/${scheduleId}/${patientId}`
  })
}
// 根据orderId获取订单详情
export const reqGetOrderInfoById = (id: string) =>
  pkRequest.get<IOrderInfo>({
    url: API_ORDER.GET_ORDERINFO_BY_ID + `/${id}`
  })
// 取消订单
export const reqCancelOrderByOrderId = (orderId: string) =>
  pkRequest.get<ICancelOrder>({
    url: API_ORDER.CANCEL_ORDER_BY_ORDERID + `/${orderId}`
  })
// 下单，根据下单号，生产支付二维码
export const reqWXPayCodeDataByOrderId = (orderId: string) =>
  pkRequest.get<IWXPayErcode>({
    url: API_ORDER.PAY_WXERCODE_BY_ORDERID + `/${orderId}`
  })
// 查询订单支付状态

export const reqQueryOrderStatus = (orderId: string) =>
  pkRequest.get<IPayResultStatus>({
    url: API_ORDER.ORDER_PAYSTATUS_BY_ORDERID + `/${orderId}`
  })
// 获取订单列表
export const reqUserOrderList = (config: IOrderConfig) => {
  const { page, limit, patientId, orderStatus } = config
  return pkRequest.get<IUserOrderList>({
    url: API_ORDER.GET_USERORDER_LIST + `/${page}/${limit}`,
    params: {
      patientId,
      orderStatus
    }
  })
}
// 获取订单状态
export const reqGetStatusList = () =>
  pkRequest.get<IOrderStatus>({
    url: API_ORDER.ORDER_STATUS_LIST
  })
// 根据就诊人id，获取订单
